package com.ruoyi.project.channel.userLevelConfig.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.userLevelConfig.domain.UserLevelConfig;
import com.ruoyi.project.channel.userLevelConfig.service.IUserLevelConfigService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 会员等级信息操作处理
 * 
 * @author CAIN
 * @date 2021-01-09
 */
@Controller
@RequestMapping("/channel/userLevelConfig")
public class UserLevelConfigController extends BaseController
{
    private String prefix = "channel/userLevelConfig";
	
	@Autowired
	private IUserLevelConfigService userLevelConfigService;
	
	@RequiresPermissions("channel:userLevelConfig:view")
	@GetMapping()
	public String userLevelConfig()
	{
	    return prefix + "/userLevelConfig";
	}
	
	/**
	 * 查询会员等级列表
	 */
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(UserLevelConfig userLevelConfig)
	{
		startPage();
        List<UserLevelConfig> list = userLevelConfigService.selectUserLevelConfigList(userLevelConfig);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出会员等级列表
	 */
	@RequiresPermissions("channel:userLevelConfig:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserLevelConfig userLevelConfig)
    {
    	List<UserLevelConfig> list = userLevelConfigService.selectUserLevelConfigList(userLevelConfig);
        ExcelUtil<UserLevelConfig> util = new ExcelUtil<UserLevelConfig>(UserLevelConfig.class);
        return util.exportExcel(list, "userLevelConfig");
    }
	
	/**
	 * 新增会员等级
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存会员等级
	 */
	@RequiresPermissions("channel:userLevelConfig:add")
	@Log(title = "会员等级", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(UserLevelConfig userLevelConfig)
	{		
		return toAjax(userLevelConfigService.insertUserLevelConfig(userLevelConfig));
	}

	/**
	 * 修改会员等级
	 */
	@GetMapping("/edit/{levelId}")
	public String edit(@PathVariable("levelId") Integer levelId, ModelMap mmap)
	{
		UserLevelConfig userLevelConfig = userLevelConfigService.selectUserLevelConfigById(levelId);
		mmap.put("userLevelConfig", userLevelConfig);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存会员等级
	 */
	@RequiresPermissions("channel:userLevelConfig:edit")
	@Log(title = "会员等级", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(UserLevelConfig userLevelConfig)
	{		
		return toAjax(userLevelConfigService.updateUserLevelConfig(userLevelConfig));
	}
	
	/**
	 * 删除会员等级
	 */
	@RequiresPermissions("channel:userLevelConfig:remove")
	@Log(title = "会员等级", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(userLevelConfigService.deleteUserLevelConfigByIds(ids));
	}

	/**
	 * 用户状态修改
	 */
	@Log(title = "用户管理", businessType = BusinessType.UPDATE)
	@RequiresPermissions("channel:userLevelConfig:edit")
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(UserLevelConfig userLevelConfig) {
		return toAjax(userLevelConfigService.updateUserLevelConfig(userLevelConfig));
	}
}
